import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
//引入全局样式
import "./assets/styles/common.css";
import "./assets/styles/el-reset.css"; //用于重设element-ul样式

// Vue.config.productionTip = false;//产品模式打开，开发模式关闭
Vue.use(ElementUI);

// 判断条件如果有token就放行
// 如果没有跳转到登录界面
router.beforeEach(function(to, from, next) {
  let token = localStorage.getItem("qf-token");
  if (token) {
    next();
  } else {
    // 如果是登录页，放行
    // 其他页面，跳转到登录页
    if (to.path === "/login") {
      next();
    } else {
      next({ path: "/login" });
    }
  }
  // console.log(to)
  // console.log(from)
  // next()
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
